package com.pioneer.gui.invoice.controller;

import com.pioneer.gui.invoice.model.InvoiceModel;
import com.pioneer.gui.invoice.model.VectorList;
import com.pioneer.gui.invoice.view.Confirmation;
import com.pioneer.gui.invoice.view.InvoicePanel;
import com.pioneer.gui.invoice.util.Constants;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;

import java.util.Vector;

public class InvoiceSelection
implements ActionListener,Constants
{
	//private JComboBox jComboBox;
	private InvoiceModel invoiceModel;
	//private InvoicePanel invoicePanel;

	public InvoiceSelection(InvoiceModel model)
	{
		//this.jComboBox=jComboBox;
		//this.invoicePanel=invoicePanel;
		this.invoiceModel=model;		
	}

	public void actionPerformed(ActionEvent e)
	{
		if  ((this.invoiceModel.getEditStatus()==InvoiceModel.CHANGED)&& ((this.invoiceModel.getEntryStatus()==null) || ( (this.invoiceModel.getEntryStatus()!=null)&&(this.invoiceModel.getEntryStatus().equals(ENTERED)))))
		{		
			Confirmation confirm=new Confirmation("Do you want to save changes?","You have made changes to:"+this.invoiceModel.getEditStatusMessage(),this.invoiceModel);			
		}		
		//VectorList invoiceList=(VectorList)this.jComboBox.getModel();
		VectorList invoiceList=(VectorList)invoiceModel.getInvoiceId();
		Object obj=invoiceList.getDatabaseKey();
		if (obj==null)
			return;
		String selectedInvoiceNo=obj.toString();		
		this.invoiceModel.loadInvoice();
	}
}